package com.zzh;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;

public class MapDemo {
    public static void main(String[] args) {
        test3();
}
public static void test0() {
    Map<String,Double> map = new HashMap<>();
    map.put("张三", 99.0);
    map.put("李四", 98.0);
    map.put("王五", 97.0);
    map.put("赵六", 96.0);
    map.put("孙七", 95.0);
    System.out.println(map);

    map.remove("张三");
    System.out.println(map);

    boolean containsKey = map.containsKey("张三");
    System.out.println("containsKey = "+containsKey);
    boolean containsValue = map.containsValue(98.0);
    System.out.println("containsValue = "+containsValue);

    boolean  empty = map.isEmpty();
    System.out.println("empty = "+empty);
    int size = map.size();
    System.out.println("size = "+size);


    }

public static void test1() {

    Map<String,Double> map = new HashMap<>();
    map.put("张三", 99.0);
    map.put("李四", 98.0);
    map.put("王五", 97.0);
    map.put("赵六", 96.0);
    map.put("孙七", 95.0);
    Set<String> keySet = map.keySet();
    for (String key : keySet) {
        //根据key获取value
        Double value = map.get(key);
        System.out.println(key+"---"+value);
    }
}
public static void test2() {

        Map<String,Double> map = new HashMap<>();
        map.put("张三", 99.0);
        map.put("李四", 98.0);
        map.put("王五", 97.0);
        map.put("赵六", 96.0);
        map.put("孙七", 95.0);
        //1.将map集合转成set集合（将map中的key-value绑定成一个对象entry）
        Set<Map.Entry<String, Double>> entrySet = map.entrySet();
        //2.遍历set集合
        for (Map.Entry<String, Double> entry : entrySet) {
            //3.根据entry获取key和value
            String key =entry.getKey();
            Double value = entry.getValue();
            System.out.println(key+"---"+value);

        }
    }
    public static void test3() {
        Map<String,Double> map = new HashMap<>();
        map.put("张三", 99.0);
        map.put("李四", 98.0);
        map.put("王五", 97.0);
        map.put("赵六", 96.0);
        map.put("孙七", 95.0);

        map.forEach((key, value) -> System.out.println(key + "---" + value));

    }

    public static void test4() {
        Map<String,Double> map = new HashMap<>();
        map.put("张三", 99.0);
        map.put("李四", 98.0);
        map.put("王五", 97.0);
        map.put("赵六", 96.0);
        map.put("孙七", 95.0);
    }
}

